<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>XXX后台管理</title>
    <script src="js/jquery-3.2.1.js"></script>
    <script src="layui/layui.js"></script>
    <script src="layui/lay/modules/layer.js"></script>
    <link rel="stylesheet" type="text/css" href="layui/css/layui.css">
    <link rel="stylesheet" type="text/css" href="layui/css/modules/layer/default/layer.css">
</head>
<body>
<div style="display: flex;justify-content: space-between">
    <div id="searchDiv" style="display: flex;justify-content: flex-start;margin-top: 8px;width: 30%">
        <label style="text-align: left;padding: 8px 0" class="layui-form-label">搜索</label>
        <input id="search_content" style="margin-right:10px;" type="text" name="title" required lay-verify="required"
               placeholder="请输入..." autocomplete="off" class="layui-input">
        <button class="layui-btn" data-type="reload">搜索</button>
    </div>
    <form style="display: flex;justify-content: flex-end;margin-top: 8px" method="post" class="layui-form"
          action="/manager/addShengfen">
        <div style="margin: 0;padding: 0" class="layui-form-item">
            <label class="layui-form-label">演出时长</label>
            <div class="layui-input-block">
                <input type="text" name="publish_time" required lay-verify="required" placeholder="请输入时长（需加单位）"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div style="margin: 0;padding: 0" class="layui-form-item">
            <label class="layui-form-label">价格</label>
            <div class="layui-input-block">
                <input type="text" name="publish_price" required lay-verify="required" placeholder="请输入价格（无需写单位）"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div style=";margin: 0;padding: 0" class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo">添加</button>
            </div>
        </div>
    </form>
</div>
<table id="demo" lay-filter="test"></table>
<script>


    layui.use('table', function () {
        var table = layui.table;

        //第一个实例
        table.render({
            elem: '#demo'
            , height: 500
            , url: 'getFeeScaleByPd_id/?pd_id=${pd_id}' //数据接口
            , cols: [[ //表头
                {
                    field: 'manager_id',
                    title: '编号',
                    width: 80,
                    align: 'center',
                    sort: true,
                    fixed: 'left',
                    templet: '#indexID'
                }
                , {field: 'publish_time', align: 'center', sort: true, title: '演出时间'}
                , {field: 'publish_price', align: 'center', sort: true, title: '价格'}
                , {field: 'pd_title', align: 'center', title: '节目名称'}
                , {field: 'title', title: '删除', align: 'center', width: 200, templet: '#shanchu', event: 'shanchu'}
            ]]
            , id: 'testReload'
            , page: false //开启分页
        });

        var $ = layui.$, active = {
            reload: function () {
                var demoReload = $('#search_content');
                //执行重载
                table.reload('testReload', {
                    url: 'searchFeeScale?pd_id=${pd_id}'
                    , page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    , where: {
                        title: demoReload.val()
                    }
                });
            }
        };
        $('#searchDiv .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });


        table.on('tool(test)', function (obj) {
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的DOM对象
            //删除
            if (layEvent === 'shanchu') { //删除
                layer.confirm('确定将 ' + data.pd_title + ' 的 ' + data.publish_time + ' - ' + data.publish_price + ' 删除吗？', function (index) {
                    //向服务端发送删除指令
                    $.ajax({
                        type: "post",
                        url: "deleteFeeScale",
                        data: {"feeScale_id": data.feeScale_id},
                        success: function (res) {
                            if (res.code == 0) {
                                layer.close(index);
                                layer.msg("删除成功！", {icon: 1});
                                obj.del();
                            } else {
                                layer.msg("发生错误！", {icon: 5})
                            }
                        }
                    });
                    layer.close(index);
                });
            }
        });
    });
</script>

<script>
    //Demo
    layui.use('form', function () {
        var form = layui.form;
        //监听提交
        form.on('submit(formDemo)', function (data) {
            $.ajax({
                type: 'POST',
                url: "add_feeScale?pd_id=${pd_id}",
                data: data.field,
                async: false,
                success: function (res) {
                    if (res.code == -1) {
                        layer.msg(res.msg, {icon: 5, anim: 6});
                    } else if (res.code == 0) {
                        location.reload();
                    }
                },
                error: function (res) {
                    layer.alert("发生异常！");
                }
            });
            return false;
        });
    });
</script>

<script type="text/html" id="lahei">
    <a href="javascript:;" class="layui-table-link">拉黑/恢复</a>
</script>
<script>
    //回车事件绑定
    $('#search_content').bind('keyup', function (event) {
        if (event.keyCode == "13") {
            //回车执行查询
            $('#searchDiv .layui-btn').click();
        }
    });
</script>
<script type="text/html" id="status">
    {{#  if(d.manager_status ==1){ }}
    正常
    {{#  } }}
    {{#  if(d.manager_status ==-1){ }}
    <span style="color: red"> 黑名单</span>
    {{#  } }}
</script>

<script type="text/html" id="indexID">
    {{ d.LAY_INDEX }}
</script>
<script type="text/html" id="role">
    <a href="FindObjectManagerRolers_page?manager_id={{d.manager_id}}" class="layui-table-link">查看角色</a>
</script>

<script type="text/html" id="shanchu">
    <a href="javascript:;" class="layui-table-link">删除</a>
</script>
<script type="text/html" id="weihu">
    <a href="findManagerInfo?manager_id={{d.manager_id}}" class="layui-table-link">维护</a>
</script>
</body>
</html>